package org.jash.wechat2205;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.gson.Gson;

import org.jash.wechat2205.entity.Res;
import org.jash.wechat2205.utils.ApiService;
import org.jash.wechat2205.utils.NetUtils;

import java.io.IOException;

import javax.xml.transform.Result;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {
    private TextView tv;
    private ImageView image;
    private ApiService service;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.tv);
        image = findViewById(R.id.image);
        service = NetUtils.getRetrofit().create(ApiService.class);
//        service.sendRCode("13812312313").enqueue(new Callback<Res>() {
//
//            @Override
//            public void onResponse(Call<Res> call, Response<Res> response) {
//                runOnUiThread(() -> tv.setText("" + response.body().getData()));
//            }
//
//            @Override
//            public void onFailure(Call<Res> call, Throwable throwable) {
//
//            }
//        });
//        service.sendRCode("13812312313").execute(res -> {
//            tv.setText("" + res.getData());
//        }, t -> {
//            Log.e("TAG", "onCreate: ", t);
//        });
        service.sendRCode("13812312313")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(res ->
                                tv.setText("" + res.getData()),
                        t ->
                                Log.e("TAG", "onCreate: ", t));


    }
}